<?php
/**
 * Путь к методу контроллера MVC
 * @author Akulov Denis
 * @since 02.06.2011
 */
class MVC_Path implements MVC_Path_Interface {

    /**
     * Объект корректирующий MVC - путь.
     * @var MVC_PathCorrector_Interface
     */
    private $_objPathCorrector = null;


    // Запрос в виде строки, если есть.
    private $_strRequest = '';
    // Знак - разделитель в запросе
    private $_strRequestDelimiter = '/';


    // Распарсеный путь
    private $_strControllerName = '';
    private $_strMethodName = '';
    private $_arParams = array ();


    public function getController () {
        return $this->_strControllerName;
    }


    /**
     * @param MVC_PathCorrector_Interface $objMVCPathCorrector
     */
    public function setMvcPathCorrector (MVC_PathCorrector_Interface $objMvcPathCorrector) {
        $this->_objPathCorrector = $objMvcPathCorrector;
    }


    /**
     * @return MVC_PathCorrector
     */
    private function getMvcPathCorrector () {
        return $this->_objPathCorrector;
    }

    /**
     * @param string $strRequest
     */
    public function setRequest ($strRequest) {
        $strRequest = $this->getMvcPathCorrector()->requestCorrect($strRequest);
        $arRequest = explode($this->_strRequestDelimiter, $strRequest);
        $this->setController($arRequest[0]);
        $this->setMethod($arRequest[1]);
        unset($arRequest[0]);
        unset($arRequest[1]);
        $this->setParam(array_values($arRequest));
    }


    /**
     * @param string $strRequestDelimiter
     */
    public function setRequestDelimiter ($strRequestDelimiter) {
        $this->_strRequestDelimiter = $strRequestDelimiter;
    }


    /**
     * @param string $strController
     * @return MVC_Path
     */
    public function setController ($strController) {
        $this->_strControllerName = $this->getMvcPathCorrector()
                                        ->controllerCorrect($strController);
        return $this;
    }


    public function getMethod () {
        return $this->_strMethodName;
    }


    public function getMethodPost () {
        return '_post'.ucfirst($this->_strMethodName);
    }



    /**
     * @param string $strMethod
     * @return MVC_Path
     */
    public function setMethod ($strMethod) {
        $this->_strMethodName = $this->getMvcPathCorrector()
                                 ->methodCorrect($strMethod);
        return $this;
    }


    public function getParam () {
        return $this->_arParams;
    }


    /**
     * @param array[] $arParam
     */
    public function setParam($arParam)
    {
        $this->_arParams = $this->getMvcPathCorrector()
                               ->paramCorrect($arParam);
    }
}